Skip to content

Conversation

@wenju-he
Copy link
Contributor

@wenju-he wenju-he commented Mar 14, 2025

Change scope and memory semantics type from Enum from int, similar as in PR #17438.
volatile/const is removed from function parameter pointer type, to align with SVP-IR and clang/lib/Sema/SPIRVBuiltins.td.

…PIRVBuiltins.td

Change scope and memory semantics type from Enum from int, similar
as in PR intel#17438.
volatile is removed from function parameter pointer type, to align with
SVP-IR and clang/lib/Sema/SPIRVBuiltins.td.
When long long and another type, e.g. long, are used in a same test,
there is error:
sycl/__spirv/spirv_ops.hpp:337:17: note: candidate function not viable: no known conversion from 'long *' to '__global long long *' for 1st argument
Copy link
Contributor

@frasercrmck frasercrmck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you!

Should there be clang tests for these new builtins? I've not really been following the upstream clang/SPIR-V side of things.

Comment on lines 337 to 341
__SPIRV_ATOMICS(__SPIRV_ATOMIC_FLOAT, _Float16)
__SPIRV_ATOMICS(__SPIRV_ATOMIC_FLOAT, float)
__SPIRV_ATOMICS(__SPIRV_ATOMIC_FLOAT, double)
__SPIRV_ATOMICS(__SPIRV_ATOMIC_SIGNED, int)
__SPIRV_ATOMICS(__SPIRV_ATOMIC_SIGNED, long)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remove this part and below unsigned int/long variants because when a test uses both long long type from this header and non-long long type from clang SPIRVBuiltins.td, there is build error

using AtomicRefT =
    atomic_ref<long long, memory_order::relaxed, memory_scope::device>;

using AtomicRefT2 =
    atomic_ref<long, memory_order::relaxed, memory_scope::device>;
In file included from Regression/pf-wg-atomic64.cpp:9:
In file included from intel-llvm/build/bin/../include/sycl/atomic_ref.hpp:13:
In file included from intel-llvm/build/bin/../include/sycl/ext/oneapi/experimental/address_cast.hpp:11:
intel-llvm/build/bin/../include/sycl/detail/spirv.hpp:654:10: error: no matching function for call to '__spirv_AtomicIAdd'
  654 |   return __spirv_AtomicIAdd(Ptr, SPIRVScope, SPIRVOrder, Value);
      |          ^~~~~~~~~~~~~~~~~~
intel-llvm/build/bin/../include/sycl/atomic_ref.hpp:311:27: note: in instantiation of function template specialization 'sycl::detail::spirv::AtomicIAdd<long, sycl::access::address_space::generic_space, sycl::access::decorated::no>' requested here
  311 |     return detail::spirv::AtomicIAdd(ptr, scope, order, operand);
      |                           ^
intel-llvm/build/bin/../include/sycl/atomic_ref.hpp:319:12: note: in instantiation of member function 'sycl::detail::atomic_ref_impl<long, 4, sycl::memory_order::relaxed, sycl::memory_scope::device, sycl::access::address_space::generic_space>::fetch_add' requested here
  319 |     return fetch_add(operand) + operand;
      |            ^
Regression/pf-wg-atomic64.cpp:45:19: note: in instantiation of member function 'sycl::detail::atomic_ref_impl<long, 4, sycl::memory_order::relaxed, sycl::memory_scope::device, sycl::access::address_space::generic_space>::operator+=' requested here
   45 |           feature += 42;
      |                   ^
intel-llvm/build/bin/../include/sycl/__spirv/spirv_ops.hpp:337:17: note: candidate function not viable: no known conversion from 'long *' to '__global long long *' for 1st argument
  337 | __SPIRV_ATOMICS(__SPIRV_ATOMIC_SIGNED, long long)
      | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
intel-llvm/build/bin/../include/sycl/__spirv/spirv_ops.hpp:334:3: note: expanded from macro '__SPIRV_ATOMICS'
  334 |   macro(__attribute__((opencl_global)), Arg)                                   \
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
intel-llvm/build/bin/../include/sycl/__spirv/spirv_ops.hpp:303:3: note: expanded from macro '__SPIRV_ATOMIC_SIGNED'
  303 |   __SPIRV_ATOMIC_BASE(AS, Type)                                                \
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
intel-llvm/build/bin/../include/sycl/__spirv/spirv_ops.hpp:296:3: note: expanded from macro '__SPIRV_ATOMIC_BASE'
  296 |   __SPIRV_ATOMIC_IADD(AS, Type)                                                \
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
intel-llvm/build/bin/../include/sycl/__spirv/spirv_ops.hpp:249:37: note: expanded from macro '__SPIRV_ATOMIC_IADD'
  249 |   extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicIAdd(                        \
      |                                     ^

Please advise how to proceed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's linked to this I think https://github.com/intel/llvm/pull/1384/files#diff-73b1c844b6929ccc37836285e2d87f89ead7074c6693a80e712f06bb54fa5cb2, I'll need to refresh my memory and come back to you as it is a bit old now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep the declarations in sycl/include/sycl/__spirv/spirv_ops.hpp until there is a stable solution. I'll check it later.

Copy link
Contributor

@elizabethandrews elizabethandrews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add FE tests

@wenju-he
Copy link
Contributor Author

Please add FE tests

added in e630132

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@wenju-he
Copy link
Contributor Author

@intel/dpcpp-cfe-reviewers please review again, thanks

@wenju-he wenju-he changed the title [SYCL] Move SPIR-V atomic builtins declarations into clang/lib/Sema/SPIRVBuiltins.td [SYCL] Add SPIR-V atomic builtins declarations to clang/lib/Sema/SPIRVBuiltins.td Apr 10, 2025
@wenju-he
Copy link
Contributor Author

@intel/llvm-gatekeepers please merge, thanks

@kbenzie kbenzie merged commit 0a65094 into intel:sycl Apr 21, 2025
37 of 38 checks passed
@wenju-he wenju-he deleted the move-atomic-builtin-to-SPIRVBuiltins.td branch April 21, 2025 09:45
extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicXor( \
AS Type *P, __spv::Scope::Flag S, __spv::MemorySemanticsMask::Flag O, \
Type V);
extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicXor(AS Type *P, int S, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, why do we still need these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aelovikov-intel it is related to long long type, please check comment: #17471 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants